<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <!-- 

    -->
    <!-- 准备一个容器 -->
    <div id="root">
        <h1>学校信息</h1>
        <h2>学校名称：{{name}}</h2>
        <h2>学校地址：{{address}}</h2>
        <h2>校长名称：{{name}}</h2>
        <hr/>
        <h1>学生信息</h1>
        <button @click="addsex">添加一个性别属性，默认值是男</button>
        <h2>姓名：{{student.name}}</h2>
        <h2 v-if="student.sex">性别：{{student.sex}}</h2>
        <h2>年龄：真实{{student.age.rAge}}，对外{{student.age.sAge}}</h2>
        <h2>朋友们</h2>
        <ul>
            <li v-for="(f,index) in student.friends" :key="index">
                {{f.name}}--{{f.age}}
            </li>
        </ul>
    </div>
</body>
    <script>
        const vm = new Vue({
            el:'#root',
            data:{
                name:'郑航',
                address:'郑州',
                name:'可爱的人',
                student:{
                    name:'张三',
                    age:{
                        rAge:'18',
                        sAge:'55'
                    },
                    friends:[
                        {name:'李四',age:19},
                        {name:'王五',age:20},
                        {name:'赵六',age:21}
                    ]
                }

            },
            methods:{
                updateMei(){
                    // 奏效
                    // this.persons[0].name = '马老师',
                    // this.persons[0].age = 50,
                    // this.persons[0].sex = '男'

                    // 失效
                    this.persons[0] =                     {
                        id:'001',
                        name:'马老师',
                        age:50,
                        sex:'男'
                    }
                }
            },
            methods:{
                addsex() {
                    // Vue.set(this.student,'sex','男')
                    this.$set(this.student,'sex','女')
                }
            }
        })
    </script>
</html>